Project (PARADIS)
cmake_minimum_required(VERSION 2.8)

set(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Message (STATUS "PARADIS_BINARY_DIR = " ${PARADIS_BINARY_DIR})
Message (STATUS "PARADIS_SOURCE_DIR = " ${PARADIS_SOURCE_DIR})

Set(CMAKE_C_COMPILER "mpicc")
Set(CMAKE_CXX_COMPILER "mpicxx")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")  
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")  

FIND_PACKAGE( OpenMP REQUIRED)  
if(OPENMP_FOUND)  
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")  
    message(STATUS "OpenMP_C_FLAGS = " ${OpenMP_C_FLAGS})  
    message(STATUS "OpenMP_CXX_FLAGS = " ${OpenMP_CXX_FLAGS})  
    message(STATUS "OpenMP_EXE_LINKER_FLAGS = " ${OpenMP_EXE_LINKER_FLAGS})  
endif()  

Find_Package(GEOS)
Message(STATUS "include and lib " ${GEOS_INCLUDE_DIR} " " ${GEOS_LIB_DIR})
IF(GEOS_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GEOS_C_FLAGS}")  
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GEOS_CXX_FLAGS}")  
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GEOS_EXE_LINKER_FLAGS}")  
    message(STATUS "GEOS_C_FLAGS = " ${GEOS_C_FLAGS})  
    message(STATUS "GEOS_CXX_FLAGS = " ${GEOS_CXX_FLAGS})  
    message(STATUS "GEOS_EXE_LINKER_FLAGS = " ${GEOS_EXE_LINKER_FLAGS})  
    Message(STATUS "GEOS_INCLUDE_DIR = " ${GEOS_INCLUDE_DIR})
    Message(STATUS "GEOS_LINK_DIR = " ${GEOS_LINK_DIR})
ENDIF(GEOS_FOUND)

Message(STATUS "CMAKE_C_FLAGS = " ${CMAKE_C_FLAGS})
Message(STATUS "CMAKE_CXX_FLAGS = " ${CMAKE_CXX_FLAGS})
Message(STATUS "CMAKE_EXE_LINKER_FLAGS = " ${CMAKE_EXE_LINKER_FLAGS})

Add_subdirectory (src)
Add_subdirectory (utilities)

ENABLE_TESTING()

Set(frlen 1200,1800)
Set(cubel 3000)
Set(maxSeg 200)
Set(nfrs 5)
Set(angle 1.5707963)
Set(maxDensity 1E13)
String(RANDOM LENGTH 5 ALPHABET 0123456789 seed)
Message(STATUS "random seed for test is " ${seed})

Set(commands_gen_bicrystal -type 3 -frlen ${frlen} -cubel ${cubel} -maxseg ${maxSeg} -nfrsrcs ${nfrs} -seed ${seed} 
    -polycrystal 1 -nGrain 2 -pbc 7 -maxDensity ${maxDensity}
    -TBAngle ${angle} 
    -twinRatio 0.5 -heightRatio 2 -deltaNum 0 -nLayers 1) 

ADD_TEST(gen_bicrystal utilities/paradisgen ${commands_gen_bicrystal})

Set(commands_repart -infile paradis.data -cells 4 -domains 1,1,4 -outfile bicrystal.data)
Add_Test(repart_gen utilities/paradisrepart ${commands_repart})

Set(mpirun_commands -n 4 "./src/paradis")
Set(paradis_commands -n 2 -d ${PARADIS_BINARY_DIR}/bicrystal.data ${PARADIS_SOURCE_DIR}/tests/bicrystal.ctrl)
Add_Test(run_paradis_bicrystal "mpirun" ${mpirun_commands} ${paradis_commands})

if(0)
message(STATUS "CMAKE_C_FLAGS = " ${CMAKE_C_FLAGS})
message(STATUS "CMAKE_C_FLAGS_DEBUG = " ${CMAKE_C_FLAGS_DEBUG})
message(STATUS "CMAKE_C_FLAGS_MINSIZEREL = " ${CMAKE_C_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_C_FLAGS_RELEASE = " ${CMAKE_C_FLAGS_RELEASE})
message(STATUS "CMAKE_C_FLAGS_RELWITHDEBINFO = " ${CMAKE_C_FLAGS_RELWITHDEBINFO})

message(STATUS "CMAKE_CXX_FLAGS = " ${CMAKE_CXX_FLAGS})
message(STATUS "CMAKE_CXX_FLAGS_DEBUG = " ${CMAKE_CXX_FLAGS_DEBUG})
message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL = " ${CMAKE_CXX_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_CXX_FLAGS_RELEASE = " ${CMAKE_CXX_FLAGS_RELEASE})
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO = " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})

message(STATUS "CMAKE_EXE_LINKER_FLAGS = " ${CMAKE_EXE_LINKER_FLAGS})
message(STATUS "CMAKE_EXE_LINKER_FLAGS_DEBUG = " ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
message(STATUS "CMAKE_EXE_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE = " ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})

message(STATUS "CMAKE_MODULE_LINKER_FLAGS = " ${CMAKE_MODULE_LINKER_FLAGS})
message(STATUS "CMAKE_MODULE_LINKER_FLAGS_DEBUG = " ${CMAKE_MODULE_LINKER_FLAGS_DEBUG})
message(STATUS "CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_MODULE_LINKER_FLAGS_RELEASE = " ${CMAKE_MODULE_LINKER_FLAGS_RELEASE})
message(STATUS "CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO})

message(STATUS "CMAKE_SHARED_LINKER_FLAGS = " ${CMAKE_SHARED_LINKER_FLAGS})
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_DEBUG = " ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE = " ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO})

message(STATUS "CMAKE_STATIC_LINKER_FLAGS = " ${CMAKE_STATIC_LINKER_FLAGS})
message(STATUS "CMAKE_STATIC_LINKER_FLAGS_DEBUG = " ${CMAKE_STATIC_LINKER_FLAGS_DEBUG})
message(STATUS "CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELEASE = " ${CMAKE_STATIC_LINKER_FLAGS_RELEASE})
message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO})

endif()
